Wang Haihua
🚅 🚋😜 🚑 🚔
print("Hello World!")
Hello World!
Python runs the code line by line:
print("Hello1")
print("Hello2")
print("Hello3")
print("Welcome to Our Python course")
Hello1 Hello2 Hello3 Welcome to Our Python course
If you make mistakes, python will complain:
print("Hello')
File "<ipython-input-3-21f0c5b97628>", line 1 print("Hello') ^ SyntaxError: EOL while scanning string literal
print "Hello World"
File "<ipython-input-4-2e860ebf713e>", line 1 print "Hello World" ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Hello World")?
print(Hello)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-5-85bf5114fa6b> in <module> ----> 1 print(Hello) NameError: name 'Hello' is not defined
!python --version
Python 3.8.5
#this is where I print "Hello World"
#taking some notes
#take a note
n = 1
print(n)
1
p = n
print(p)
1
#swapping
data1 = 7
data2 = 12
data3 = 23
data4 = 33
data1, data2, data3 , data4 = data2 , data1, data4, data3
print(data1, data2, data3, data4)
12 7 33 23
print("data1:", data1, "data:", data2)
data1: 12 data: 7
Think of this as a sequence of characters
M | y | n | a | m | e | i | s | G | a | b | b | y | |||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
#String
hello = "World"
print(hello) #print variable
print("World") #print value
print(n)
World World 1
type('x')
str
#type()
type(hello)
str
print(type(hello)) #print data type
<class 'str'>
#Integer
int_value = 5
int_value
5
print(type(int_value))
<class 'int'>
t = 3.19
print(type(t))
<class 'float'>
#Boolean
t, f = True, False
print(type(t))
print(t)
print(f)
<class 'bool'> True False
len("Python")
6
len("Welcome to the Turkish AI Hub")
29
hello
'World'
print(len(hello)) #print data length
5
p
1
len(5)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-26-91fed648bb37> in <module> ----> 1 len(5) TypeError: object of type 'int' has no len()
len(15.6)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-27-79577706af1a> in <module> ----> 1 len(15.6) TypeError: object of type 'float' has no len()
data22 = "Data Science"
len(data22)
12
len("Data Science")
12
name = "Omer"
print(name)
name = name + " Cengiz"
print(name)
Omer Omer Cengiz
#F-string
name = "Turkey"
print(f'hello {name}')
hello Turkey
name2 = "Aslı"
print("Hello {}".format(name2))
Hello Aslı
data12 = 5
data13 = 90
print("My value:{} and Your value:{}".format(data12, data13))
My value:5 and Your value:90
print(f'My value: {data12} and your value: {data13}')
My value: 5 and your value: 90
print("My value:", str(data12), "Your Value:", str(data13))
My value: 5 Your Value: 90
Operator | Name |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
// | Floor division |
** | Exponentiaion |
% | Modulus |
These operators can be used like the following:
35+67
102
#exponential numbers
5**2
25
5**3
125
x = 10
print(x+2)
12
y = 13
print(y/2)
print(y//2)
print(y % 2)
6.5 6 1
x = "35" + 67
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-41-e19ba8062dfb> in <module> ----> 1 x = "35" + 67 TypeError: can only concatenate str (not "int") to str
my_string = "hello" + "world"
print(my_string)
helloworld
my_string = "35"*3
print(my_string)
353535
my_string = "hello"*4
print(my_string)
hellohellohellohello
z = 5
z += 1 # this statement equals to z= z+1 , meaning while the previous value of z is 5, the new z value becomes 6.
z
6
z += 2 #z = z + 2
z
8
z *= 2 # z = z * 2
z
16
my_string = "hey"
print(my_string)
my_string += " there"
print(my_string)
my_string *= 2
print(my_string)
hey hey there hey therehey there
"""
These quotes are used for docstrings. They are often confused with comments. But python will treat this as a regular string
"""
'\nThese quotes are used for docstrings. They are often confused with comments. But python will treat this as a regular string\n'